package com.xez.util
{
	
	import com.xez.data.DirRoot;
	import com.xez.data.FsRoot;
	import com.xez.data.User;
	import com.xez.data.WebRoot;
	
	import flash.desktop.NativeApplication;
	import flash.net.SharedObject;
	
	public class FsData
	{
		public function FsData()
		{
			if (so.data.isFirstRun == undefined)
			{
				isFirstRun = true;
				
				so.data.isFirstRun = false;
				so.flush();
			}
			else
				isFirstRun = false;
		}
		
		private static var instance:FsData;
		
		public static function getInstance():FsData
		{
			if (!instance)
				instance = new FsData();
			
			return instance;
		}
		
		[Bindable]
		public var curFsRoot:FsRoot = new FsRoot();
		
		[Bindable]
		public var curWebRoot:WebRoot;
		
		[Bindable]
		public var curDirRoot:DirRoot;
		
		[Bindable]
		public var user:User;
		
		public var newVersion:String;
		public var newAppurl:String;
		
		[Bindable]
		public var auto:Boolean = true;
		
		[Bindable]
		public var hasUser:Boolean = true;
		
		public var isFirstRun:Boolean;
		
		public var so:SharedObject = SharedObject.getLocal('fsdata');
		
		// SECURE PASSWORD
		private var _securePassword:String;
		
		public function get securePassword():String
		{
			return so.data.securePassword;
		}
		
		public function set securePassword(value:String):void
		{
			so.data.securePassword = value;
			so.flush();
		}
		
		// HAS SECURE PASSWORD
		private var _hasSecurePassword:Boolean = false;
		
		public function get hasSecurePassword():Boolean
		{
			return securePassword && securePassword != '';
		}
		
		private var _curVersion:String = null;
		
		public function get curVersion():String
		{
			if (!_curVersion)
			{
				var localXML:XML = NativeApplication.nativeApplication.applicationDescriptor;
				var nss:Namespace = localXML.namespace();
				_curVersion = localXML.nss::versionNumber;
			}
			
			return _curVersion;
		}
		
		public function get hasTipImageOperationMsg():Boolean
		{
			if (so.data.hasTipImageOperationMsg == undefined)
			{
				hasTipImageOperationMsg = true;
				return false;
			}
			else
				return true;
		}
		
		public function  set hasTipImageOperationMsg(value:Boolean):void
		{
			so.data.hasTipImageOperationMsg = true;
		}
		
		public function init():void
		{
			// 获取缓存的用户信息
			user = new User();
			user.getFromLocal();
			
			// 获取基本信息 版本
			DataUtil.getInstance().getBase();
			
			// 初始化WebView数据
			curFsRoot.load();
		}
		
	}
}